﻿using AutoMapper;
using B.S.Filtration.Domain.到货检验;
using B.S.Filtration.ErrorCode;
using B.S.Filtration.Read.Api.Application.Command.到货检验.PurchaseOrderCommand;
using MediatR;
using SqlSugar;

namespace B.S.Filtration.Read.Api.Application.CommandHander.到货检验.PurchaseOrderHandler
{
    public class GetPurchaseOrderHandler : IRequestHandler<GetPurchaseOrderCommand, APIResult<List<PurchaseOrder>>>
    {
        private readonly ISqlSugarClient db;
        private readonly IMapper mapper;
        public GetPurchaseOrderHandler(ISqlSugarClient db, IMapper mapper)
        {
            this.db = db;
            this.mapper = mapper;
        }
        public async Task<APIResult<List<PurchaseOrder>>> Handle(GetPurchaseOrderCommand request, CancellationToken cancellationToken)
        {

            APIResult<List<PurchaseOrder>> result = new APIResult<List<PurchaseOrder>>();

            var list = await db.Queryable<PurchaseOrder>().ToListAsync();
            result.data = list;
            if (result.data != null)
            {
                result.code = APIResultCode.success;
                result.msg = "显示成功";
            }
            else
            {
                result.code = APIResultCode.failed;
                result.msg = "显示失败";
            }

            return result;
        }
    }
}
